﻿using System;
using System.Threading.Tasks;
using K9Nano.Web.Accounts.Dto;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace K9Nano.Web.Accounts
{
   // [ApiController]
    [AllowAnonymous]
    [Route("account/[action]")]
    public abstract class AccountController : Controller
    {
        protected readonly IAccountAppService AccountAppService;

        protected AccountController(IAccountAppService accountAppService)
        {
            AccountAppService = accountAppService;
        }
        

        [HttpPost]
        public virtual IActionResult Register()
        {
            return Ok();
        }

        [HttpGet]
        public virtual async Task<UserInfoDto> UserInfo()
        {
            if (User.Identity.IsAuthenticated)
            {
                return await AccountAppService.GetUserInfo();
            }

            return new UserInfoDto
            {
                Name = "游客"
            };
        }

        [HttpPost]
        public virtual async Task<Guid> Create([FromBody] UserCreateInput input)
        {
            return await AccountAppService.CreateAsync(input, HttpContext.RequestAborted);
        }
    }
}